<template>
    <div class="app_content">
        <div class="table_qy">
            <div style="text-align: right;padding-right: 20px;" class="middle lb_title">
                <span style="float: left;margin-top: 7px;">角色管理信息</span>
                <el-button type="primary" size="mini" @click="addYjjs()">新增一级角色</el-button>
            </div>
            <div class="table_padding" style="padding-bottom: 10px;">
                <div class="table_content">
                    <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;margin-top: 15px" row-key="jsid"
                              border class="table_overflow" :style="{height: scrollerHeight}"
                              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column prop="jsid" label="角色ID"></el-table-column>
                        <el-table-column prop="jsmc" label="角色名称"></el-table-column>
                        <el-table-column prop="" label="角色类型">
                            <template slot-scope="scope">
                                <span v-if="scope.row.jslx === 1">系统内置</span>
                                <span v-else-if="scope.row.jslx === 2">自建角色</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="fjsid" label="父角色ID"></el-table-column>
                        <el-table-column prop="pxh" label="排序号"></el-table-column>
                        <el-table-column prop="countZy" label="拥有资源">
                            <template slot-scope="scope">
                                <a href="javascript:void(0)" @click="yyzy(scope.row.jsid)">{{scope.row.countZy}}</a>
                            </template>
                        </el-table-column>
                        <el-table-column prop="countYh" label="角色下用户">
                            <template slot-scope="scope">
                                <a href="javascript:void(0)" @click="jsxyh(scope.row.jsid)">{{scope.row.countYh}}</a>
                            </template>
                        </el-table-column>
                        <el-table-column prop="" label="操作" width="250">
                            <template slot-scope="scope">
                                <el-button size="small" @click="modifyJs(scope.row)" type="text">修改</el-button>
                                <el-button size="small" type="text" @click="delJs(scope.row)">删除</el-button>
                                <el-button size="small" type="text" @click="addZjs(scope.row)">新增子角色</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>

            <!--新增修改弹窗-->
            <el-dialog :visible.sync="addDialogVisible" width="25%" :title="dialogTitle"
                       :close-on-click-modal="false" @close="closeJs('jsForm')">
                <el-form ref="jsForm" :model="js" :rules="rules" label-width="100px" label-position="right">
                    <el-form-item label="父角色ID" prop="fjsid" style="display: none">
                        <el-input v-model="js.fjsid"/>
                    </el-form-item>
                    <el-form-item label="角色ID" prop="jsid">
                        <el-input v-model="js.jsid" placeholder="必填" size="mini" :readonly="dialogType === 'edit'"/>
                    </el-form-item>
                    <el-form-item label="角色名称" prop="jsmc">
                        <el-input v-model="js.jsmc" placeholder="必填" size="mini"/>
                    </el-form-item>
                    <el-form-item label="角色类型" prop="jslx">
                        <el-select v-model="js.jslx" placeholder="请选择" size="mini" style="width: 100%">
                            <el-option
                                    v-for="item in jslxOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="排序号">
                        <el-input v-model="js.pxh" size="mini"/>
                    </el-form-item>
                </el-form>
                <div style="text-align:center;padding-top: 10px">
                    <el-button type="primary" size="mini" @click="confirm('jsForm')">确定</el-button>
                    <el-button type="primary" v-if="dialogType === 'edit'" size="mini" @click="changeFjsid()">修改父节点
                    </el-button>
                    <el-button type="warning" size="mini" @click="closeJs('jsForm')">取消</el-button>
                </div>
            </el-dialog>

            <!--拥有资源弹窗-->
            <el-dialog :visible.sync="yyzyDialogVisible" width="25%" title="拥有资源"
                       :close-on-click-modal="false" @close="ziyuan_cancel()">
                <div style="height:500px;width: 100%;padding: 10px;">
                    <el-input v-model="yyzy_jsid" style="display: none"/>
                    <el-scrollbar wrap-class="scrollbar-wrapper">
                        <el-tree default-expand-all show-checkbox ref="tree" node-key="gnzyid" :props="defaultProps"
                                 :data="zyData" :default-checked-keys="checkedData">

                        </el-tree>
                    </el-scrollbar>
                    <div style="text-align:center;padding-top: 25px">
                        <el-button type="primary" size="mini" @click="ziyuan_save()">确定</el-button>
                        <el-button type="warning" size="mini" @click="ziyuan_cancel()">取消</el-button>
                    </div>
                </div>
            </el-dialog>

            <!--角色下用户弹窗-->
            <el-dialog :visible.sync="jsxyhDialogVisible" width="70%" title="角色下用户"
                       :close-on-click-modal="false" @close="">
                <div style="height:calc(100% - 50px);width: 100%;padding: 10px;">
                    <el-form :inline="true" :model="listQuery" ref="searchForm" class="demo-form-inline">
                        <el-form-item label="工学号/姓名：">
                            <el-input v-model="listQuery.idxm" placeholder="工学号/姓名" size="mini"
                                      style="width: 150px"></el-input>
                        </el-form-item>
                        <el-form-item label="用户状态：">
                            <el-select v-model="listQuery.yhzt" placeholder="请选择" size="mini" style="width: 150px">
                                <el-option
                                        v-for="item in yhztOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="匹配方式：">
                            <el-select v-model="listQuery.ppfs" placeholder="请选择" size="mini" style="width: 150px">
                                <el-option
                                        v-for="item in ppfsOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="findJsxyhlist(sxjsid)" size="mini" class="button_search">
                                查询
                            </el-button>
                            <el-button type="info" @click="jsxyhReset()" size="mini" class="button_reset">重置</el-button>
                            <el-button type="primary" @click="rygl_add()" size="mini">新增</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table :data="jsxyhData" stripe border class="table_overflow"
                              style="margin-top: 15px;height: 350px">
                        <el-table-column prop="yhid" label="职工号" width="100"></el-table-column>
                        <el-table-column prop="jsid" v-if="false"></el-table-column>
                        <el-table-column prop="sfmsjh" v-if="false"></el-table-column>
                        <el-table-column prop="xm" label="用户姓名" width="150"></el-table-column>
                        <el-table-column prop="bmmc" label="部门"></el-table-column>
                        <el-table-column prop="jsmx" label="角色明细"></el-table-column>
                        <el-table-column prop="" label="操作" width="150">
                            <template slot-scope="scope">
                                <el-button size="small" @click="editJsmx(scope.row)" type="text">编辑角色明细</el-button>
                                <el-button size="small" @click="delJsyh(scope.row)" type="text">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pageIn">
                        <el-pagination
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="currentPage"
                                :page-sizes="[10, 20, 30, 40]"
                                :page-size="pageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="pageTotal">
                        </el-pagination>
                    </div>
                </div>
            </el-dialog>

            <!--为角色新增用户弹窗-->
            <el-dialog :visible.sync="yhxxDialogVisible" width="50%" title="用户信息"
                       :close-on-click-modal="false" @close="">
                <div style="height:calc(100% - 50px);width: 100%;padding: 10px;">
                    <el-form :inline="true" :model="yhxxListQuery" ref="searchForm" class="demo-form-inline">
                        <el-form-item label="工学号/姓名：">
                            <el-input v-model="yhxxListQuery.idxm" placeholder="工学号/姓名" size="mini"
                                      style="width: 150px"></el-input>
                        </el-form-item>
                        <el-form-item label="用户状态：">
                            <el-select v-model="yhxxListQuery.yhzt" placeholder="请选择" size="mini" style="width: 150px">
                                <el-option
                                        v-for="item in yhztOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="findYhList()" size="mini">查询</el-button>
                            <el-button type="warning" @click="yhxxReset()" size="mini">重置</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table :data="yhxxData" stripe border class="table_overflow"
                              style="margin-top: 15px;height: 350px">
                        <el-table-column prop="yhid" label="职工号" width="100"></el-table-column>
                        <el-table-column prop="xm" label="用户姓名" width="150"></el-table-column>
                        <el-table-column prop="bmmc" label="部门"></el-table-column>
                        <el-table-column prop="" label="操作" width="130">
                            <template slot-scope="scope">
                                <el-button size="small" @click="drJsyh(scope.row)" type="text">调入</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pageIn">
                        <el-pagination
                                @size-change="yhxxHandleSizeChange"
                                @current-change="yhxxHandleCurrentChange"
                                :current-page="yhxxCurrentPage"
                                :page-sizes="[10, 20, 30, 40]"
                                :page-size="yhxxPageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="yhxxPageTotal">
                        </el-pagination>
                    </div>
                </div>
            </el-dialog>

            <!--查看角色明细-->
            <el-dialog :visible.sync="jsmxDialogVisible" width="50%" title="角色明细"
                       :close-on-click-modal="false" @close="">
                <div style="height:calc(100% - 50px);width: 100%;padding: 10px;">
                    <el-button type="primary" @click="addYhjsmx()" size="mini" style="float: right">新增</el-button>
                    <el-table :data="jsmxData" stripe border class="table_overflow"
                              style="margin-top: 40px;height: 350px">
                        <el-table-column prop="id" v-if="false"></el-table-column>
                        <el-table-column prop="bmm" v-if="false"></el-table-column>
                        <el-table-column prop="jsid" v-if="false"></el-table-column>
                        <el-table-column prop="jsmc" label="角色名称" width="100"></el-table-column>
                        <el-table-column prop="yhid" label="职工号" width="150"></el-table-column>
                        <el-table-column prop="xm" label="姓名" width="150"></el-table-column>
                        <el-table-column prop="bmmc" label="部门"></el-table-column>
                        <el-table-column prop="" label="操作" width="130">
                            <template slot-scope="scope">
                                <el-button size="small" @click="delJsmx(scope.row)" type="text">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pageIn">
                        <el-pagination
                                @size-change="jsmxHandleSizeChange"
                                @current-change="jsmxHandleCurrentChange"
                                :current-page="jsmxCurrentPage"
                                :page-sizes="[10, 20, 30, 40]"
                                :page-size="jsmxPageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="jsmxPageTotal">
                        </el-pagination>
                    </div>
                </div>
            </el-dialog>
            <!--新增角色明细-->
            <el-dialog :visible.sync="yhjsmxDialogVisible" width="30%" title="新增角色明细"
                       :close-on-click-modal="false" @close="">
                <div style="height:calc(100% - 50px);width: 100%;padding: 10px;">
                    <el-form :model="yhjsmx" ref="yhjsmxForm" class="demo-form-inline" :rules="yhjsmxRule"
                             :label-position="labelPosition" label-width="140px">
                        <el-form-item label="职工号：" prop="yhid">
                            <el-input v-model="yhjsmx.yhid" style="width: 180px;" size="mini" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="用户姓名：" prop="xm">
                            <el-input v-model="yhjsmx.xm" style="width: 180px" size="mini" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="部门：" prop="bmm">
                            <el-select v-model="yhjsmx.bmm" filterable placeholder="请选择" size="mini"
                                       style="width: 180px">
                                <el-option
                                        v-for="item in bmmOptions"
                                        :key="item.bmm"
                                        :label="item.bmmc"
                                        :value="item.bmm">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                    <div style="text-align:center;padding-top: 20px">
                        <el-button type="primary" size="mini" @click="addYhjsmx_save('yhjsmxForm')">确定</el-button>
                        <el-button type="warning" size="mini" @click="addYhjsmx_cancel('yhjsmxForm')">取消</el-button>
                    </div>
                </div>
            </el-dialog>

            <!--修改父角色ID-->
            <el-dialog :visible.sync="xgfjsidDialogVisible" width="40%" title="角色资源"
                       :close-on-click-modal="false">
                <div style="height:500px;width: 100%;padding: 10px;">
                    <el-table :data="changeJsData"
                              style="width: 100%;margin-bottom: 20px;margin-top: 15px;height: 400px" row-key="jsid"
                              border class="table_overflow" highlight-current-row @current-change="getJs"
                              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column prop="jsid" label="角色ID"></el-table-column>
                        <el-table-column prop="jsmc" label="角色名称"></el-table-column>
                        <el-table-column prop="fjsid" label="父角色ID" v-if="false"></el-table-column>
                    </el-table>
                    <div style="text-align:center;padding-top: 20px">
                        <el-button type="primary" size="mini" @click="fjsid_xg">确定</el-button>
                        <el-button type="warning" size="mini" @click="fjsid_cancel">取消</el-button>
                    </div>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    import {
        findList,
        findOne,
        del,
        add,
        update,
        findCountZycdjs,
        findYyzylistAll,
        findJsxyhlist,
        updateJsxzy,
        findYhList,
        addJsyh,
        delJsyh,
        findYhjsmxList,
        findBmlist,
        findYhbmCount,
        addYhjsmx,
        deleteYhjsmx,
        updateFjsid
    } from '@/api/app/xtgl0301/jsgl.js'
    import {deepClone} from "../../../../utils"; /* 引入接口文件 定义接口别名 */

    const defaultJs = {
        jsid: '',
        jsmc: '',
        jslx: '',
        fjsid: '',
        pxh: '',
        gzlgwtbfs: '',
        countZy: 0,
        countYh: 0
    }

    export default {
        name: "jsgl",
        data() {
            return {
                js: Object.assign({}, defaultJs),
                tableData: [],                  //列表数据集合
                scrollerHeight: "",
                jslxOptions: [{
                    label: '系统内置',
                    value: 1
                }, {
                    label: '自建角色',
                    value: 2
                }],
                addDialogVisible: false,
                yyzyDialogVisible: false,
                jsxyhDialogVisible: false,
                yhxxDialogVisible: false,
                jsmxDialogVisible: false,
                yhjsmxDialogVisible: false,
                xgfjsidDialogVisible: false,
                dialogType: 'new',
                dialogTitle: '新增角色',
                yyzy_jsid: '',
                rules: {
                    jsid: [{required: true, trigger: 'blur', message: '请输入角色ID'}],
                    jsmc: [{required: true, trigger: 'blur', message: '请输入角色名称'}],
                    jslx: [{required: true, trigger: 'blur', message: '请选择角色类型'}]
                },
                defaultProps: {
                    children: 'children',
                    label: 'gnzymc',
                    id: 'gnzyid'
                },
                zyData: [],
                checkedData: [],
                currentPage: 1,                  //初始页
                pageTotal: 0,
                pageSize: 10,
                yhxxCurrentPage: 1,                  //初始页
                yhxxPageTotal: 0,
                yhxxPageSize: 10,
                jsmxCurrentPage: 1,                  //初始页
                jsmxPageTotal: 0,
                jsmxPageSize: 10,
                jsxyhData: [],
                yhxxData: [],
                jsmxData: [],
                changeJsData: [],   //修改角色父ID是的列表集合
                listQuery: {
                    idxm: null,
                    yhzt: null,
                    ppfs: null,
                },
                yhxxListQuery: {
                    idxm: null,
                    yhzt: null,
                },
                yhztOptions: [{
                    label: '停用',
                    value: 0
                }, {
                    label: '启用',
                    value: 1
                }],
                ppfsOptions: [{
                    label: '角色ID',
                    value: 0
                }, {
                    label: '身份描述',
                    value: 1
                }],
                sxjsid: '',  //所选角色ID
                sxyhid: '',   //所选用户ID
                sxyhxm: '',   //所选用户姓名
                currentRow: null,   //选中的列
                yhjsmx: {
                    jsid: '',
                    yhid: '',
                    xm: '',
                    bmm: ''
                },
                bmmOptions: [],
                labelPosition: 'right',
                yhjsmxRule: {
                    bmm: [{required: true, trigger: 'blur', message: '请选择部门'}],
                    yhid: [{trigger: 'blur', message: '未获取到用户ID'}],
                    xm: [{trigger: 'blur', message: '未获取到用户姓名'}]
                }
            }
        },
        mounted() {                             //页面初始化加载(只在页面初始时加载一次)
            this.scrollerHeight = (window.innerHeight - 185) + 'px';
            this.search();
        },
        methods: {
            async search() {
                let data = await findList()                          //请求参数路径方法为‘findList’ data返回数据
                this.tableData = data.data.content;
            },
            //新增一级角色
            addYjjs() {
                this.js = Object.assign({}, defaultJs);
                this.dialogType = 'new';
                this.dialogTitle = '新增角色';
                this.addDialogVisible = true;
            },
            //关闭窗口时处理
            closeJs(formName) {
                this.$refs[formName].clearValidate();
                this.addDialogVisible = false;
            },
            //修改角色
            modifyJs(row) {
                if (row.jslx === 1) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '系统固化角色不能修改',
                        dangerouslyUseHTMLString: true
                    });
                } else {
                    this.dialogType = 'edit';
                    this.dialogTitle = '编辑角色';
                    this.js = deepClone(row);
                    this.addDialogVisible = true;
                }
            },
            //新增/修改提交
            confirm(formName) {
                this.$refs[formName].validate(async (valid) => {
                    if (valid) {
                        delete this.js.countYh;
                        delete this.js.countZy;
                        if (this.dialogType === 'new') {
                            const data = await findOne({jsid: this.js.jsid});
                            if (data.data.content !== undefined) {
                                this.$notify({
                                    title: '警告',
                                    type: 'warning',
                                    message: '该角色ID已存在',
                                    dangerouslyUseHTMLString: true
                                });
                                return false;
                            } else {
                                this.$confirm('确定添加该角色吗?', '提示', {
                                    cancelButtonText: '取消',
                                    confirmButtonText: '确定',
                                    type: 'warning'
                                }).then(async () => {
                                    const data = await add(this.js);

                                    if (data.code === 200) {
                                        this.$notify({
                                            title: '成功',
                                            type: 'success',
                                            message: '添加成功',
                                            dangerouslyUseHTMLString: true
                                        });
                                        this.addDialogVisible = false;
                                        await this.search();
                                    } else {
                                        this.$notify({
                                            title: '失败',
                                            type: 'danger',
                                            message: '添加失败',
                                            dangerouslyUseHTMLString: true
                                        });
                                    }
                                });
                            }
                        } else {
                            this.$confirm('确定修改该角色吗?', '提示', {
                                cancelButtonText: '取消',
                                confirmButtonText: '确定',
                                type: 'warning'
                            }).then(async () => {
                                const data = await update(this.js);

                                if (data.code === 200) {
                                    this.$notify({
                                        title: '成功',
                                        type: 'success',
                                        message: '修改成功',
                                        dangerouslyUseHTMLString: true
                                    });
                                    this.addDialogVisible = false;
                                    await this.search();
                                } else {
                                    this.$notify({
                                        title: '失败',
                                        type: 'danger',
                                        message: '修改失败',
                                        dangerouslyUseHTMLString: true
                                    });
                                }
                            });
                        }
                    }
                });
            },
            //删除角色（只能删除自建角色）
            delJs(row) {
                if (row.jslx === 1) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '系统固化角色不能删除',
                        dangerouslyUseHTMLString: true
                    });
                } else if (row.countZy !== 0 || row.countYh !== 0) {
                    this.$confirm('该角色下存在用户或者资源,确定要删除吗?', '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        type: 'warning'
                    }).then(async () => {
                        let parms = {
                            jsid: row.jsid
                        }

                        //查询该角色下的子角色
                        let res = await findCountZycdjs(parms);

                        if (res.code === 200) {
                            if (res.data.content !== 0) {
                                this.$notify({
                                    title: '警告',
                                    type: 'warning',
                                    message: "该角色下存在子角色，不可删除！清空角色下的子角色之后再进行操作",
                                    dangerouslyUseHTMLString: true
                                });
                            } else {
                                let data = await del(parms);

                                if (data.code === 200) {
                                    this.$notify({
                                        title: '成功',
                                        type: 'success',
                                        message: '删除成功',
                                        dangerouslyUseHTMLString: true
                                    });
                                    await this.search();
                                } else {
                                    this.$notify({
                                        title: '失败',
                                        type: 'danger',
                                        message: data[0].message,
                                        dangerouslyUseHTMLString: true
                                    });
                                }
                            }
                        } else {
                            this.$notify({
                                title: '失败',
                                type: 'danger',
                                message: "查询该角色下的子角色失败",
                                dangerouslyUseHTMLString: true
                            });
                        }
                    });
                } else {
                    this.$confirm('确定删除该角色吗?', '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        type: 'warning'
                    }).then(async () => {
                        let parms = {
                            jsid: row.jsid
                        }

                        //查询该角色下的子角色
                        let res = await findCountZycdjs(parms);

                        if (res.code === 200) {
                            if (res.data.content !== 0) {
                                this.$notify({
                                    title: '警告',
                                    type: 'warning',
                                    message: "该角色下存在子角色，不可删除！清空角色下的子角色之后再进行操作",
                                    dangerouslyUseHTMLString: true
                                });
                            } else {
                                let data = await del(parms);

                                if (data.code === 200) {
                                    this.$notify({
                                        title: '成功',
                                        type: 'success',
                                        message: '删除成功',
                                        dangerouslyUseHTMLString: true
                                    });
                                    await this.search();
                                } else {
                                    this.$notify({
                                        title: '失败',
                                        type: 'danger',
                                        message: "删除失败",
                                        dangerouslyUseHTMLString: true
                                    });
                                }
                            }
                        } else {
                            this.$notify({
                                title: '失败',
                                type: 'danger',
                                message: "查询该角色下的子角色失败",
                                dangerouslyUseHTMLString: true
                            });
                        }
                    });
                }
            },
            //新增子角色
            addZjs(row) {
                this.js = Object.assign({}, defaultJs);
                this.dialogTitle = '新增子角色';
                this.dialogType = 'new';
                this.addDialogVisible = true;
                this.js.fjsid = row.jsid;
            },
            //点击拥有资源，弹出功能资源窗口
            async yyzy(jsid) {
                this.yyzy_jsid = jsid;
                //查询所有资源
                let data = await findYyzylistAll({jsid: jsid});
                if (data.code === 200) {
                    const res = JSON.parse(data.data.content);

                    this.zyData = res.gnzyList;

                    for (let i = 0; i < res.jszyList.length; i++) {
                        this.checkedData.push(res.jszyList[i].gnzyid);
                    }
                } else {
                    this.$notify({
                        title: '失败',
                        type: 'danger',
                        message: "获取资源列表失败",
                        dangerouslyUseHTMLString: true
                    });
                    return false;
                }
                this.yyzyDialogVisible = true;
            },
            //拥有资源管理窗口确定按钮
            async ziyuan_save() {
                const gnzyid = [];
                const arr = this.$refs.tree.getCheckedNodes();
                for (let i = 0; i < arr.length; i++) {
                    gnzyid.push(arr[i].gnzyid);
                }
                let parms = {
                    gnzyid: gnzyid,
                    jsid: this.yyzy_jsid,
                }

                this.$confirm('确定修改功能资源信息吗?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning'
                }).then(async () => {
                    const data = await updateJsxzy(parms);

                    if (data.code === 200) {
                        this.$notify({
                            title: '成功',
                            type: 'success',
                            message: '修改成功',
                            dangerouslyUseHTMLString: true
                        });
                        this.yyzyDialogVisible = false;
                        await this.search();
                    } else {
                        this.$notify({
                            title: '失败',
                            type: 'danger',
                            message: '修改失败',
                            dangerouslyUseHTMLString: true
                        });
                    }
                });
            },
            ziyuan_cancel() {
                this.zyData = [];
                this.checkedData = [];
                this.yyzyDialogVisible = false;
            },
            //角色下用户弹窗
            jsxyh(jsid) {
                this.sxjsid = jsid;
                this.findJsxyhlist(jsid);
                this.jsxyhDialogVisible = true;
            },
            //查询角色下用户列表
            async findJsxyhlist(jsid) {
                let parms = {
                    jsid: jsid,
                    ppfs: this.listQuery.ppfs,
                    yhzt: this.listQuery.yhzt,
                    idxm: this.listQuery.idxm,
                    page: this.currentPage,
                    pageSize: this.pageSize
                }
                let data = await findJsxyhlist(parms);
                this.jsxyhData = data.data.content;
                this.pageTotal = data.data.pageInfo.total;
            },
            //每页显示条数改变事件
            handleSizeChange(val) {
                this.pageSize = val;
                this.findJsxyhlist(this.sxjsid);
            },
            //当前页数改变事件
            handleCurrentChange(val) {
                this.currentPage = val;
                this.findJsxyhlist(this.sxjsid);
            },
            //查询条件重置
            jsxyhReset() {
                this.listQuery.idxm = null;
                this.listQuery.sfzj = null;
                this.listQuery.ppfs = null;
                this.findJsxyhlist(this.sxjsid);
            },
            //新增角色下用户
            async rygl_add() {
                this.findYhList();

                this.yhxxDialogVisible = true;
            },
            //查询所有用户信息
            async findYhList() {
                let parms = {
                    jsid: this.sxjsid,
                    yhzt: this.yhxxListQuery.yhzt,
                    idxm: this.yhxxListQuery.idxm,
                    page: this.yhxxCurrentPage,
                    pageSize: this.yhxxPageSize
                }
                let data = await findYhList(parms);
                this.yhxxData = data.data.content;
                this.yhxxPageTotal = data.data.pageInfo.total;
            },
            yhxxReset() {
                this.yhxxListQuery.idxm = null;
                this.yhxxListQuery.sfzj = null;
                this.findYhList();
            },
            //每页显示条数改变事件
            yhxxHandleSizeChange(val) {
                this.yhxxPageSize = val;
                this.findYhList();
            },
            //当前页数改变事件
            yhxxHandleCurrentChange(val) {
                this.yhxxCurrentPage = val;
                this.findYhList();
            },
            //调入用户到角色下
            async drJsyh(row) {
                this.$confirm('确定调入该用户吗?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning'
                }).then(async () => {
                    let parms = {
                        jsid: this.sxjsid,
                        yhid: row.yhid
                    };
                    let data = await addJsyh(parms);

                    if (data.code === 200) {
                        this.$notify({
                            title: '成功',
                            type: 'success',
                            message: '调入成功',
                            dangerouslyUseHTMLString: true
                        });
                        await this.findYhList();
                        await this.findJsxyhlist(this.sxjsid);
                    } else {
                        this.$notify({
                            title: '失败',
                            type: 'danger',
                            message: '调入失败',
                            dangerouslyUseHTMLString: true
                        });
                    }
                });
            },
            //删除角色用户
            delJsyh(row) {
                if (row.sfmsjh !== undefined) {
                    this.$notify({
                        title: '警告',
                        type: 'warning',
                        message: "该用户根据身份描述匹配，不能删除",
                        dangerouslyUseHTMLString: true
                    });
                } else {
                    this.$confirm('确定删除该用户吗?', '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        type: 'warning'
                    }).then(async () => {
                        let parms = {
                            jsid: row.jsid,
                            yhid: row.yhid
                        };
                        let data = await delJsyh(parms);

                        if (data.code === 200) {
                            this.$notify({
                                title: '成功',
                                type: 'success',
                                message: '删除成功',
                                dangerouslyUseHTMLString: true
                            });
                            await this.findJsxyhlist(this.sxjsid);
                            await this.search();
                        } else {
                            this.$notify({
                                title: '失败',
                                type: 'danger',
                                message: '删除失败',
                                dangerouslyUseHTMLString: true
                            });
                        }
                    });
                }
            },
            //编剧角色明细
            editJsmx(row) {
                this.jsmxData = [];
                this.sxyhid = row.yhid;
                this.sxyhxm = row.xm;
                this.getYhjsmxlist(this.sxjsid, this.sxyhid);
                this.jsmxDialogVisible = true;
            },
            //查询用户下角色明细
            async getYhjsmxlist(jsid, yhid) {
                let parms = {
                    jsid: jsid,
                    yhid: yhid,
                    page: this.yhxxCurrentPage,
                    pageSize: this.yhxxPageSize
                }
                let data = await findYhjsmxList(parms);
                this.jsmxData = data.data.content;
                this.jsmxPageTotal = data.data.pageInfo.total;
            },
            //每页显示条数改变事件
            jsmxHandleSizeChange(val) {
                this.jsmxPageSize = val;
                this.getYhjsmxlist(this.sxjsid, this.sxyhid);
            },
            //当前页数改变事件
            jsmxHandleCurrentChange(val) {
                this.jsmxCurrentPage = val;
                this.getYhjsmxlist(this.sxjsid, this.sxyhid);
            },
            //添加用户角色明细
            async addYhjsmx() {
                this.yhjsmx.yhid = this.sxyhid;
                this.yhjsmx.jsid = this.sxjsid;
                this.yhjsmx.xm = this.sxyhxm;
                let data = await findBmlist();
                this.bmmOptions = data.data.content;

                this.yhjsmxDialogVisible = true;
            },
            //取消添加用户角色明细
            addYhjsmx_cancel(formName) {
                this.$refs[formName].clearValidate();
                this.yhjsmxDialogVisible = false;
            },
            //添加用户角色明细
            addYhjsmx_save(formName) {
                this.$refs[formName].validate(async (valid) => {
                    if (valid) {
                        let data = await findYhbmCount({bmm: this.yhjsmx.bmm, yhid: this.yhjsmx.yhid});
                        var info = "是否确定添加？";
                        if (data.data.content === 0) {
                            info = "用户不在相应部门下，" + info;
                        }

                        this.$confirm(info, '提示', {
                            cancelButtonText: '取消',
                            confirmButtonText: '确定',
                            type: 'warning'
                        }).then(async () => {
                            const data = await addYhjsmx(this.yhjsmx);

                            if (data.code === 200) {
                                this.$notify({
                                    title: '成功',
                                    type: 'success',
                                    message: '添加成功',
                                    dangerouslyUseHTMLString: true
                                });
                                this.yhjsmxDialogVisible = false;
                                await this.getYhjsmxlist(this.sxjsid, this.sxyhid);
                                await this.findJsxyhlist(this.sxjsid);
                            } else {
                                this.$notify({
                                    title: '失败',
                                    type: 'danger',
                                    message: '添加失败',
                                    dangerouslyUseHTMLString: true
                                });
                            }
                        });
                    }
                });
            },
            //删除角色明细
            delJsmx(row) {
                this.$confirm("确定删除该用户角色明细吗？", '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning'
                }).then(async () => {
                    let parms = {
                        id: row.id,
                        jsid: row.jsid,
                        yhid: row.yhid,
                        bmm: row.bmm
                    };
                    const data = await deleteYhjsmx(parms);

                    if (data.code === 200) {
                        this.$notify({
                            title: '成功',
                            type: 'success',
                            message: '添加成功',
                            dangerouslyUseHTMLString: true
                        });
                        await this.getYhjsmxlist(this.sxjsid, this.sxyhid);
                        await this.findJsxyhlist(this.sxjsid);
                    } else {
                        this.$notify({
                            title: '失败',
                            type: 'danger',
                            message: '添加失败',
                            dangerouslyUseHTMLString: true
                        });
                    }
                });
            },
            //修改父角色ID
            async changeFjsid() {
                let data = await findList()
                this.changeJsData = data.data.content;
                this.xgfjsidDialogVisible = true;
            },
            //获取选中的角色列
            getJs(val) {
                this.currentRow = val;
            },
            //保存新的父角色ID
            fjsid_xg() {
                if (this.currentRow.jsid === this.js.jsid) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '操作不合理！不能挂在自己角色下',
                        dangerouslyUseHTMLString: true
                    });
                } else if (this.currentRow.fjsid !== undefined && this.currentRow.fjsid === this.js.jsid) {
                    this.$notify({
                        title: '提示',
                        type: 'warning',
                        message: '操作不合理！不能挂在自己的子角色下',
                        dangerouslyUseHTMLString: true
                    });
                } else {
                    this.$confirm("确定修改该角色的父角色ID吗？", '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        type: 'warning'
                    }).then(async () => {
                        var parms = {
                            fjsid: this.currentRow.jsid,
                            jsid: this.js.jsid
                        }
                        let data = await updateFjsid(parms);

                        if (data.code === 200) {
                            this.$notify({
                                title: '成功',
                                type: 'success',
                                message: '添加成功',
                                dangerouslyUseHTMLString: true
                            });
                            this.xgfjsidDialogVisible = false;
                            this.addDialogVisible = false;
                            await this.search();
                        } else {
                            this.$notify({
                                title: '失败',
                                type: 'danger',
                                message: '添加失败',
                                dangerouslyUseHTMLString: true
                            });
                        }
                    });
                }
            },
            //关闭修改窗口
            fjsid_cancel() {
                this.xgfjsidDialogVisible = false;
            }
        }
    }
</script>

<style scoped>
    @import "../../../../styles/app0301.scss";
</style>
